import { createContainer, Lifetime, asValue, asFunction, asClass, InjectionMode, } from 'awilix';
import restComponent from '../lib/decorations/restComponent';
import autowired from '../lib/decorations/autowired';

export default function getConfiguredContainer(router) {
    const container = createContainer();


    restComponent(container, router);
    autowired(container);
    console.log("register start");
    container.loadModules(
        ['../app/**/*.js'],
        {
            cwd: __dirname,
            resolverOptions: {
                // We can give these auto-loaded modules
                // the deal of a lifetime! (see what I did there?)
                // By default it's `TRANSIENT`.
                lifetime: Lifetime.SINGLETON,
                // We can tell Awilix what to register everything as,
                // instead of guessing. If omitted, will inspect the
                // module to determinw what to register as.
                register: asClass
            }

        }
    );
    console.log("register end");


    return container;

}